#include "VideoUpdater.h"
#include "StreamPreviewWidget.h"

VideoUpdater::VideoUpdater(StreamPreviewWidget *lpWidget) : m_lpWidget(lpWidget)
{
}

VideoUpdater::~VideoUpdater(void)
{
}

void VideoUpdater::run()
{
	while (!m_lpWidget->m_bExit)
	{
		clock_t rtime = clock();
		m_lpWidget->updateImage();
		rtime = ((clock() - rtime) * 1000 / CLOCKS_PER_SEC) % 1000;
		long sleeping = (float(1000)/(m_lpWidget->m_nFps)) - rtime;
		QThread::msleep(sleeping > 0 ? sleeping : 0);
	}
}

void VideoUpdater::waitToExit()
{
	while (!this->isFinished())
		QThread::msleep(50);
}
